package com.soccer.soccerclub.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.soccer.soccerclub.entity.SoccerGame;
import com.soccer.soccerclub.service.SoccerGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-19
 */
@RestController
@RequestMapping("/soccer")
public class SoccerGameController {
    @Autowired
    private SoccerGameService soccerGameService;

    /**
     * 足球场次列表
     * @param page
     * @param gameName
     * @return
     */
    @GetMapping("/list")
    public R list(Page<SoccerGame> page,String gameName){
        Page<SoccerGame> pageP = soccerGameService.listPage(page,gameName);
        return R.ok(pageP);
    }

    /**
     * 添加足球场次
     * @param soccerGame
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody SoccerGame soccerGame){
        boolean save = soccerGameService.save(soccerGame);
        return R.ok(save);
    }

    /**
     * 场次修改
     * @param soccerGame
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody SoccerGame soccerGame){
        boolean update = soccerGameService.updateById(soccerGame);
        return R.ok(update);
    }

    /**
     * 删除场次
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public R delete(Integer id){
        boolean removeById = soccerGameService.removeById(id);
        return R.ok(removeById);
    }
}

